#include <head.h>

int main(int argc, char const *argv[])
{
    if (argc != 2)
    {
        printf("请输入文件名\n");
        return 0;
    }
    FILE *fp = fopen(argv[1], "r");
    FOPEN_ERR(fp);
    int chara = 0, word = 0, line = 0; // 字符数，单词数，行数
    // 统计行数
    while (!feof(fp))
    {
        char c = fgetc(fp);
        if (c == '\n')
        {
            line++;
        }
    }

    // 统计单词数和字符数
    rewind(fp);
    while (!feof(fp))
    {
        char c = fgetc(fp);
        if (c == ' ' || c == '\n' || c == '\t')
        {
            word++;
        }
        else
        {
            chara++;
        }
    }

    printf("行数：%d\n", line);
    printf("单词数：%d\n", word);
    printf("字符数：%d\n", chara);
    return 0;
}
